<template>
	<view class="main">
		<u-navbar :is-back="true" title="商品销售统计" :background="background" back-icon-color="#000000" title-color="#000"
			title-bold="true"></u-navbar>
		<view class="time">
			<view class="borders" @click="showtime">
				<view class="start">
					<view class="year">
						{{startime+' 00:00'}}
					</view>
					<!-- 	<view class="hour">
						{{times.hour}}:{{times.minute}}
					</view> -->
				</view>
				<view class="select">
					<u-icon name="arrow-down-fill" color="#979797" size="16"></u-icon>
				</view>
			</view>
			<text class="mid">至</text>
			<view class="borders" @click="showtime2">
				<view class="start">
					<view class="year">
						{{endtime+' 00:00'}}
					</view>
					<!-- <view class="hour">
						{{times2.hour}}:{{times2.minute}}
					</view> -->
				</view>
				<view class="select">
					<u-icon name="arrow-down-fill" color="#979797" size="16"></u-icon>
				</view>
			</view>
			<view class="xian">

			</view>
			<view class="serchs" @click="serch">
				查询
			</view>
		</view>
		<view class="num">
			<view class="money">
				<text>销售总额</text>
				<view>¥{{info==''?0:info.price}}</view>
			</view>
			<view class="money">
				<text>销售单量</text>
				<view>{{info==''?0:info.num}}</view>
			</view>
			<view class="money">
				<text>平均客单价</text>
				<view>¥{{info==''?0:info.AVG}}</view>
			</view>
		</view>
		<view class="tables">
			<view class="titles">
				<view>商品</view>
				<view>销售金额</view>
				<view>销售单量</view>
				<view>客单价</view>
			</view>
			<view class="td" v-for="(item,index) in info.order" :key="index">
				<view style="display: flex; flex-direction: column;
				align-items: center;">
					<text v-for="(shop,id) in item.good_info">{{shop.name}}</text>
				</view>
				<text>{{item.pay_true}}</text>
				<view style="display: flex; flex-direction: column;
				align-items: center;">
					<text v-for="(shop,id) in item.good_info">{{shop.amount}}</text>
				</view>
				<view style="display: flex; flex-direction: column;
			align-items: center;">
					<text v-for="(shop,id) in item.good_info">{{shop.price}}</text>
				</view>
			</view>

		</view>
		<u-calendar v-model="show" mode="date" @change="change"></u-calendar>
		<u-calendar v-model="show2" mode="date" @change="change2"></u-calendar>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				staryear: 150,
				background: {
					backgroundColor: '#fff'
				},

				type: '',
				show: false,
				show2: false,
				endtime: '0000-00-00',
				startime: '0000-00-00',
				info: ''
			}
		},
		onLoad() {


		},
		mounted() {

		},
		onShow() {},

		methods: {
			serch() {
				var start = new Date(this.startime).getTime()
				var end = new Date(this.endtime).getTime()
				if (end <= start) {
					uni.showToast({
						title: '时间区间选择错误',
						icon: 'none',
						duration: 700
					})
				} else if (this.startime == '' || this.endtime == '') {
					uni.showToast({
						title: '请选择时间段',
						icon: 'none',
						duration: 700
					})
				} else {
					global.$http.request({
						url: '/shopapi/order/statistics',
						data: {
							token: uni.getStorageSync('token'),
							start: this.startime,
							end: this.endtime
						}
					}).then(res => {
						console.log(res.data.data);
						this.info = res.data.data

					})
				}
			},
			showtime() {
				this.show = true
			},
			showtime2() {
				this.show2 = true
			},
			change(e) {
				console.log(e);
				this.startime = e.result
			},
			change2(e) {
				this.endtime = e.result
			},
		}
	}
</script>
<style lang="scss">
	page {
		font-family: PingFang SC;
		width: 750rpx;
		margin: 0 auto;
		background-color: #f7f7f7;

		.main {
			width: 750rpx;
			margin: 0 auto;
			display: flex;
			flex-direction: column;
			align-items: center;


			.time {
				width: 750rpx;
				padding: 35rpx 40rpx;
				display: flex;
				align-items: center;
				background: #FFFFFF;

				.mid {
					font-size: 22rpx;
					font-weight: 400;
					padding: 0 25rpx;
					color: #999999;
				}

				.borders {
					display: flex;
					align-items: center;
					border: 1px solid #CCCCCC;
					border-radius: 12rpx;

					.start {

						font-size: 22rpx;
						font-weight: 400;
						color: #000000;
						padding: 17rpx;
						border-right: 1px solid #CCCCCC;
						// display: flex;
						// flex-direction: column;
						// align-items: center;
						text-align: center;
					}

					.select {
						padding: 12rpx 10rpx;
					}
				}

				.xian {
					width: 1rpx;
					height: 100rpx;
					background: #FFFFFF;
					border: 1rpx solid #CCCCCC;
					margin: 0 29rpx 0 74rpx;
				}

				.serchs {
					margin: 16rpx 0;
					background: #FC7C33;
					border-radius: 10rpx;
					width: 124rpx;
					height: 70rpx;
					background: #FC7C33;
					text-align: center;
					line-height: 70rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #FFFFFF;
				}
			}

			.num {
				margin-top: 10rpx;
				width: 750rpx;
				padding: 42rpx 0;
				background: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: space-around;

				.money {
					display: flex;
					flex-direction: column;
					align-items: center;

					text {
						font-size: 22rpx;
						font-weight: 400;
						color: #4D4D4D;

					}

					view {
						padding-top: 16rpx;
						font-size: 30rpx;
						font-weight: 400;
						color: #000000;
					}
				}
			}

			.tables {
				width: 750rpx;

				.titles {
					display: flex;
					justify-content: space-around;
					background: #272A33;
					padding: 27rpx 0;

					view {
						width: 187.5rpx;
						text-align: center;
						font-size: 28rpx;
						font-weight: 400;
						color: #FFFFFF;
					}
				}

				.td {
					background-color: #fff;
					display: flex;
					align-items: center;

					text {
						padding: 23rpx 0;
						width: 187.5rpx;
						font-size: 26rpx;
						text-align: center;
						font-family: PingFang SC;
						font-weight: 400;
						color: #4C4C4C;
						line-height: 29rpx;

					}
				}

			}

		}
	}
</style>
